diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -12,14 +12,16 @@
 all:
 	@echo "You have no business running 'make' here; please look at the README file"
 	@exit 1
-source: ;	for i in src; do (cd $$i; make source); done
-www: ;		for i in src/xdoc examples; do (cd $$i; make www); done
+source:
+	for i in src; do $(MAKE) -C $$i $@; done
+www:
+	for i in src/xdoc examples; do $(MAKE) -C $$i $@; done
 
 clean:
-	for i in src examples contrib; do (cd $$i; make clean); done
-	rm -f nwsrcfilter *~ */*~
+	for i in src examples contrib; do $(MAKE) -C $$i $@; done
+	$(RM) nwsrcfilter *~ */*~
 clobber: clean
-	for i in src examples contrib; do (cd $$i; make clobber); done
+	for i in src examples contrib; do $(MAKE) -C $$i $@; done
 
 DATE:
 	(./echo -n "Version $(VERSION) of "; date) > DATE
@@ -39,21 +41,21 @@
 tarnames: clean source nwsrcfilter DATE
 	find . -not -type d -not -name FAQ.old -print | ./nwsrcfilter
 
-tar:	clean source nwsrcfilter DATE emacscheck
+tar: clean source nwsrcfilter DATE emacscheck
 	chmod +w src/Makefile
-	rm -rf /tmp/noweb-$(VERSION)
-	mkdir /tmp/noweb-$(VERSION)
+	$(RM) -r /tmp/noweb-$(VERSION)
+	mkdir -p /tmp/noweb-$(VERSION)
 	tar cvf - `find . ! -type d -not -name FAQ.old -print | ./nwsrcfilter` | (cd /tmp/noweb-$(VERSION) ; tar xf - )
 	(cd /tmp; tar cf - noweb-$(VERSION) ) | gzip -v > ../noweb-$(VERSION).tgz
-	rm -f ../noweb.tgz
-	(cd .. ; ln -s noweb-$(VERSION).tgz noweb.tgz)
+	$(RM) ../noweb.tgz
+	(cd .. && ln -s noweb-$(VERSION).tgz noweb.tgz)
 	chmod -w src/Makefile
 
 ctan:	clean source nwsrcfilter DATE emacscheck
 	chmod +w src/Makefile
-	(cd src; make boot)
-	rm -f ../noweb-$(VERSION)-ctan.zip
-	find ./* ! -type d -not -name FAQ.old -not -name '.git*' -print | ./nwsrcfilter | sed 's@^@noweb/@' | ( ln -s . noweb; zip ../noweb-$(VERSION)-ctan.zip -@; rm -f noweb )
+	$(MAKE) -C src boot
+	$(RM) ../noweb-$(VERSION)-ctan.zip
+	find ./* ! -type d -not -name FAQ.old -not -name '.git*' -print | ./nwsrcfilter | sed 's@^@noweb/@' | ( ln -s . noweb; zip ../noweb-$(VERSION)-ctan.zip -@; $(RM) noweb )
 	chmod -w src/Makefile
 
 emacscheck:
@@ -61,6 +63,4 @@
 	diff src/elisp/noweb-mode.el $(HOME)/emacs/noweb-mode.el
 
 checkin:
-	(cd src; make "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" checkin)
-
-
+	$(MAKE) -C src "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" $@
diff --git a/contrib/Makefile b/contrib/Makefile
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -5,9 +5,12 @@
 
 # don't do kostas; it requires gnu make (ugh)
 
-all: ;	for i in $(DIRS); do (cd $$i; make ICONC=$(ICONC) all); done
-install: ;	for i in $(DIRS); do (cd $$i; make LIB=$(LIB) BIN=$(BIN) install); done
-source: ;	for i in $(DIRS); do (cd $$i; make source); done
-clean: ;	for i in $(DIRS); do (cd $$i; make clean); done
+all:
+	for i in $(DIRS); do $(MAKE) -C $$i ICONC=$(ICONC) $@; done
+install:
+	for i in $(DIRS); do $(MAKE) -C $$i LIB=$(LIB) BIN=$(BIN) $@; done
+source:
+	for i in $(DIRS); do $(MAKE) -C $$i $@; done
+clean:
+	for i in $(DIRS); do $(MAKE) -C $$i $@; done
 clobber: clean
-
diff --git a/contrib/conrado/Makefile b/contrib/conrado/Makefile
--- a/contrib/conrado/Makefile
+++ b/contrib/conrado/Makefile
@@ -1,15 +1,16 @@
 LIB=/dev/null	# to be overridden by install
 
 .SUFFIXES: .nw .icn
-.nw.icn: ;	notangle -L'#line %-1L "%F"%N' $*.nw | cpif $*.icn
+.nw.icn:
+	notangle -L'#line %-1L "%F"%N' $< | cpif $@
 
 all: d2tex
 source: d2tex
-install:
-	cp d2tex $(LIB)/dijkstra.filter
+install: all
+	cp d2tex $(DESTDIR)$(LIB)/dijkstra.filter
 
 # TeX files.
 hospital.tex: hospital.nw d2tex
-	noweave -delay -filter ./d2tex hospital.nw > hospital.tex
+	noweave -delay -filter ./d2tex $< > $@
 clean:
-	/bin/rm -f hospital.tex *.dvi *.aux *.log *.blg *.bbl *~ 
+	$(RM) hospital.tex *.dvi *.aux *.log *.blg *.bbl *~
diff --git a/contrib/davelove/Makefile b/contrib/davelove/Makefile
--- a/contrib/davelove/Makefile
+++ b/contrib/davelove/Makefile
@@ -3,4 +3,4 @@
 source:
 install:
 clean:
-	/bin/rm -f *.dvi *.log *.aux
+	$(RM) *.dvi *.log *.aux
diff --git a/contrib/jobling/Makefile b/contrib/jobling/Makefile
--- a/contrib/jobling/Makefile
+++ b/contrib/jobling/Makefile
@@ -1,15 +1,17 @@
+BIN = /dev/null  # to be overridden
+LIB = /dev/null  # to be overridden
 PROG = correct-refs
-DOCSRC = $(PROG).tex 
-PROGSRC = $(PROG).csh 
+DOCSRC = $(PROG).tex
+PROGSRC = $(PROG).csh
 SCRIPTS = list-anchors.awk awk-scripts.awk
 
-all:    correct-refs.tex correct-refs.csh all-scripts
+all: correct-refs.tex correct-refs.csh all-scripts
 
 correct-refs.tex: correct-refs.nw
 	noweave -delay -index $< > $@
 
 correct-refs.csh: correct-refs.nw
-	notangle -Rcorrect-refs.csh $< | cpif $@
+	notangle -R$@ $< | cpif $@
 	chmod +x $@
 
 all-scripts: correct-refs.nw
@@ -17,18 +19,18 @@
 	notangle -Rawk-scripts.awk $< | cpif awk-scripts.awk
 	touch all-scripts
 
-install:
-	cp correct-refs.csh $(HOME)/bin
-	cp *.awk $(HOME)/lib
+install: correct-refs.csh all-scripts
+	cp correct-refs.csh $(DESTDIR)$(BIN)
+	cp *.awk $(DESTDIR)$(LIB)
 
 tidy:
-	-rm *~ *% *.bak *.log *.blg
+	$(RM) *~ *% *.bak *.log *.blg
 
 clean:  tidy
-	-rm *.ps *.dvi *.toc *.aux *.bbl *.dep $(PROG).shar
+	$(RM) *.ps *.dvi *.toc *.aux *.bbl *.dep $(PROG).shar
 
 realclean: clean
-	-rm $(DOCSRC) $(PROGSRC) $(SCRIPTS)
+	$(RM) $(DOCSRC) $(PROGSRC) $(SCRIPTS)
 
 shar:
 	shar README Makefile $(PROG).nw > $(PROG).shar
diff --git a/contrib/jonkrom/Makefile b/contrib/jonkrom/Makefile
--- a/contrib/jonkrom/Makefile
+++ b/contrib/jonkrom/Makefile
@@ -1,15 +1,15 @@
 LIB=/dev/null	# override for installation
 SHELL=/bin/sh
 all: noxref.krom
-	chmod +x noxref.krom
 
-install:
-	cp noxref.krom $(LIB)
+install: all
+	cp noxref.krom $(DESTDIR)$(LIB)
 
 source: noxref.krom
 
 noxref.krom: noxref.nw
-	notangle -Rnoxref noxref.nw > noxref.krom
+	notangle -Rnoxref $< > $@
+	chmod +x $@
 
 clean:
-	/bin/rm -f *.tex *.dvi *.ilg *.idx *.aux *.log *.blg *.bbl *~ *.ind noxref.krom
+	$(RM) *.tex *.dvi *.ilg *.idx *.aux *.log *.blg *.bbl *~ *.ind noxref.krom
diff --git a/contrib/kostas/Makefile.gnu b/contrib/kostas/Makefile.gnu
--- a/contrib/kostas/Makefile.gnu
+++ b/contrib/kostas/Makefile.gnu
@@ -1,6 +1,6 @@
 # Only works with Gnu make.
 
-LIB=/opt/noweb/lib
+LIB=/dev/null  # to be overridden
 ICONC=icont
 # This is supposed to be the defns.nw file in the icon directory of the distribution.
 defns=defns.nw
@@ -10,36 +10,36 @@
 .SUFFIXES: .nw .icn .tex .dvi
 
 
-all: C.filter C++.filter icon.filter oot.filter math.filter\
-     autodefs.oot autodefs.math
+all: C.filter C++.filter icon.filter oot.filter math.filter \
+	autodefs.oot autodefs.math
 
-install:
-	mv *.filter $(LIB)
-	mv autodefs.* $(LIB)
+install: all
+	cp *.filter $(DESTDIR)$(LIB)
+	cp autodefs.* $(DESTDIR)$(LIB)
 
 
 # TeX files.
-%.tex : %.nw
+%.tex: %.nw
 	$(WEAVE) $< > $@
 pp.tex: pp.nw
-	noweave -delay -autodefs icon -filter icon.filter -index pp.nw > pp.tex
-%.dvi : %.tex
+	noweave -delay -autodefs icon -filter icon.filter -index $< > $@
+%.dvi: %.tex
 	latex $<
 # Don't delete the intermediate .tex file.
-.PRECIOUS : %.tex
+.PRECIOUS: %.tex
 
 
 # Icon files.
-C.icn: pp.nw  C_translation_table
-	$(TANGLE) -R"C" pp.nw > $@
-C++.icn: pp.nw  C++_translation_table
-	$(TANGLE) -R"C++" pp.nw > $@
-icon.icn: pp.nw  icon_translation_table
-	$(TANGLE) -R"Icon" pp.nw > $@
-oot.icn: pp.nw  oot_translation_table
-	$(TANGLE) -R"OOT" pp.nw > $@
-math.icn: pp.nw  math_translation_table 
-	$(TANGLE) -R"Mathematica" pp.nw > $@
+C.icn: pp.nw C_translation_table
+	$(TANGLE) -R"C" $< > $@
+C++.icn: pp.nw C++_translation_table
+	$(TANGLE) -R"C++" $< > $@
+icon.icn: pp.nw icon_translation_table
+	$(TANGLE) -R"Icon" $< > $@
+oot.icn: pp.nw oot_translation_table
+	$(TANGLE) -R"OOT" $< > $@
+math.icn: pp.nw math_translation_table
+	$(TANGLE) -R"Mathematica" $< > $@
 
 ootdefs.icn: ootdefs.nw
 	$(TANGLE) $< $(defns) > $@
@@ -48,14 +48,14 @@
 
 
 # Executables: filters.
-%.filter : %.icn
+%.filter: %.icn
 	$(ICONC) -o $@ $<
 
 # Executables: autodefs.
 autodefs.oot: ootdefs.icn
-	$(ICONC) -o autodefs.oot ootdefs.icn
+	$(ICONC) -o $@ $<
 autodefs.math: mathdefs.icn
-	$(ICONC) -o autodefs.math mathdefs.icn
+	$(ICONC) -o $@ $<
 
 
 # Cleaning: remove all files that can be recreated from noweb sources.
@@ -69,7 +69,4 @@
 
 # Also remove the Icon files for the filters.
 clean:
-	-rm -f $(rem) C.icn C++.icn icon.icn oot.icn math.icn *.filter autodefs.*
-
-
-
+	$(RM) $(rem) C.icn C++.icn icon.icn oot.icn math.icn *.filter autodefs.*
diff --git a/contrib/kostas/Makefile.make b/contrib/kostas/Makefile.make
--- a/contrib/kostas/Makefile.make
+++ b/contrib/kostas/Makefile.make
@@ -1,6 +1,6 @@
 # Only works with Gnu make.
 
-LIB=/opt/noweb/lib
+LIB=/dev/null  # to be overridden
 ICONC=icont
 # This is supposed to be the defns.nw file in the icon directory of the distribution.
 defns=defns.nw
@@ -10,36 +10,36 @@
 .SUFFIXES: .nw .icn .tex .dvi
 
 
-all: C.filter C++.filter icon.filter oot.filter math.filter\
-     autodefs.oot autodefs.math
+all: C.filter C++.filter icon.filter oot.filter math.filter \
+	autodefs.oot autodefs.math
 
-install:
-	mv *.filter $(LIB)
-	mv autodefs.* $(LIB)
+install: all
+	cp *.filter $(DESTDIR)$(LIB)
+	cp autodefs.* $(DESTDIR)$(LIB)
 
 
 # TeX files.
-%.tex : %.nw
+%.tex: %.nw
 	$(WEAVE) $< > $@
 pp.tex: pp.nw
-	noweave -delay -autodefs icon -filter icon.filter -index pp.nw > pp.tex
-%.dvi : %.tex
+	noweave -delay -autodefs icon -filter icon.filter -index $< > $@
+%.dvi: %.tex
 	latex $<
 # Don't delete the intermediate .tex file.
-.PRECIOUS : %.tex
+.PRECIOUS: %.tex
 
 
 # Icon files.
-C.icn: pp.nw  C_translation_table
-	$(TANGLE) -R"C" pp.nw > $@
-C++.icn: pp.nw  C++_translation_table
-	$(TANGLE) -R"C++" pp.nw > $@
-icon.icn: pp.nw  icon_translation_table
-	$(TANGLE) -R"Icon" pp.nw > $@
-oot.icn: pp.nw  oot_translation_table
-	$(TANGLE) -R"OOT" pp.nw > $@
-math.icn: pp.nw  math_translation_table 
-	$(TANGLE) -R"Mathematica" pp.nw > $@
+C.icn: pp.nw C_translation_table
+	$(TANGLE) -R"C" $< > $@
+C++.icn: pp.nw C++_translation_table
+	$(TANGLE) -R"C++" $< > $@
+icon.icn: pp.nw icon_translation_table
+	$(TANGLE) -R"Icon" $< > $@
+oot.icn: pp.nw oot_translation_table
+	$(TANGLE) -R"OOT" $< > $@
+math.icn: pp.nw math_translation_table
+	$(TANGLE) -R"Mathematica" $< > $@
 
 ootdefs.icn: ootdefs.nw
 	$(TANGLE) $< $(defns) > $@
@@ -48,14 +48,14 @@
 
 
 # Executables: filters.
-%.filter : %.icn
+%.filter: %.icn
 	$(ICONC) -o $@ $<
 
 # Executables: autodefs.
 autodefs.oot: ootdefs.icn
-	$(ICONC) -o autodefs.oot ootdefs.icn
+	$(ICONC) -o $@ $<
 autodefs.math: mathdefs.icn
-	$(ICONC) -o autodefs.math mathdefs.icn
+	$(ICONC) -o $@ $<
 
 
 # Cleaning: remove all files that can be recreated from noweb sources.
@@ -69,7 +69,4 @@
 
 # Also remove the Icon files for the filters.
 clean:
-	-rm -f $(rem) C.icn C++.icn icon.icn oot.icn math.icn *.filter autodefs.*
-
-
-
+	$(RM) $(rem) C.icn C++.icn icon.icn oot.icn math.icn *.filter autodefs.*
diff --git a/contrib/leew/Makefile b/contrib/leew/Makefile
--- a/contrib/leew/Makefile
+++ b/contrib/leew/Makefile
@@ -3,4 +3,4 @@
 install:
 source:
 clean:
-	/bin/rm -f nocond *.dvi *.log *.aux *.toc *.tex *.tex nocond.1
+	$(RM) nocond *.dvi *.log *.aux *.toc *.tex *.tex nocond.1
diff --git a/contrib/norman/Makefile b/contrib/norman/Makefile
--- a/contrib/norman/Makefile
+++ b/contrib/norman/Makefile
@@ -1,10 +1,14 @@
 LIB=/dev/null	# to be overridden
 DIRS=numarkup
 
-all: ;	for i in $(DIRS); do (cd $$i; make ICONC=$(ICONC) ICONT=$(ICONT) all); done
-install: ;	for i in $(DIRS); do (cd $$i; make LIB=$(LIB) BIN=$(BIN) install); done
-source: ;	for i in $(DIRS); do (cd $$i; make source); done
-clean: ;	for i in $(DIRS); do (cd $$i; make clean); done
+all:
+	for i in $(DIRS); do $(MAKE) -C $$i ICONC=$(ICONC) ICONT=$(ICONT) $@; done
+install:
+	for i in $(DIRS); do $(MAKE) -C $$i LIB=$(LIB) BIN=$(BIN) $@; done
+source:
+	for i in $(DIRS); do $(MAKE) -C $$i $@; done
+clean:
+	for i in $(DIRS); do $(MAKE) -C $$i $@; done
 iconlib:	# cheap hack for slackmake
 	true
 
diff --git a/contrib/norman/numarkup/Makefile b/contrib/norman/numarkup/Makefile
--- a/contrib/norman/numarkup/Makefile
+++ b/contrib/norman/numarkup/Makefile
@@ -6,32 +6,31 @@
 OBJS = main.o pass1.o latex.o input.o scraps.o names.o arena.o global.o
 
 .SUFFIXES: .nw
-.nw.c: ;	notangle -R"$@"'*' -L $< | cpif $@
-.nw.h: ;	notangle -R"$@" $< | cpif $@
+.nw.c:
+	notangle -R"$@"'*' -L $< | cpif $@
+.nw.h:
+	notangle -R"$@" $< | cpif $@
 
-all: 
+all:
 	noweb -t numarkup.nw
-	make $(TARGET)
+	$(MAKE) $(TARGET)
 
-install:
-	noweb -t numarkup.nw
-	make $(TARGET)
+install: all
 	strip $(TARGET)
-	cp $(TARGET) $(LIB)
+	cp $(TARGET) $(DESTDIR)$(LIB)
 
 source: main.c pass1.c latex.c input.c scraps.c names.c arena.c global.c
 
 clean:
-	rm -f *.o *.c *.h *.tex *.log *.dvi *~ *.blg $(TARGET) *.html *~
+	$(RM) *.o *.c *.h *.tex *.log *.dvi *~ *.blg $(TARGET) *.html *~
 
 $(OBJS): global.h
 
 $(TARGET): $(OBJS)
-	$(CC) -o $(TARGET) $(OBJS)
+	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
 
 numarkup.html: numarkup.nw
-	noweave -filter l2h -html -index numarkup.nw > numarkup.html
+	noweave -filter l2h -html -index $< > $@
 
 numarkup.tex: numarkup.nw
-	noweb -o numarkup.nw
-
+	noweb -o $@
diff --git a/contrib/ydirson/Makefile b/contrib/ydirson/Makefile
--- a/contrib/ydirson/Makefile
+++ b/contrib/ydirson/Makefile
@@ -1,6 +1,6 @@
-LIB=/dev/null   # to be overridden 
+LIB=/dev/null   # to be overridden
 
-FILTERS = guesslang inheritlang enscript-html 
+FILTERS = guesslang inheritlang enscript-html
 
 # nothing to tangle or weave
 all:
@@ -8,4 +8,4 @@
 clean:
 
 install:
-	cp -p $(FILTERS) $(LIB)
+	cp -p $(FILTERS) $(DESTDIR)$(LIB)
diff --git a/examples/Makefile b/examples/Makefile
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -4,14 +4,19 @@
 NOWEAVE=noweave
 
 .SUFFIXES: .i3 .m3 .nw .tex .dvi .html
-.nw.html: ;	$(NOWEAVE) -filter l2h -filter btdefn -index -html $*.nw > $*.html
-.nw.tex: ;	$(NOWEAVE) -index -filter btdefn $*.nw > $*.tex
-.nw.i3:	;	$(NOTANGLE) -Rinterface -L'<* LINE %L "%F" *>%N' $*.nw > $*.i3
-.nw.m3:	;	$(NOTANGLE) -L'<* LINE %L "%F" *>%N' $*.nw > $*.m3
-.tex.dvi: ;	latex '\scrollmode \input '"$*"; while grep -s 'Rerun to get cross-references right' $*.log; do latex '\scrollmode \input '"$*"; done
+.nw.html:
+	$(NOWEAVE) -filter l2h -filter btdefn -index -html $< > $@
+.nw.tex:
+	$(NOWEAVE) -index -filter btdefn $< > $@
+.nw.i3:
+	$(NOTANGLE) -Rinterface -L'<* LINE %L "%F" *>%N' $< > $@
+.nw.m3:
+	$(NOTANGLE) -L'<* LINE %L "%F" *>%N' $< > $@
+.tex.dvi:
+	latex '\scrollmode \input '"$*"; while grep -s 'Rerun to get cross-references right' $*.log; do latex '\scrollmode \input '"$*"; done
 
 HTML=breakmodel.html compress.html dag.html graphs.html mipscoder.html primes.html \
-     scanner.html test.html tree.html wc.html wcni.html
+	scanner.html test.html tree.html wc.html wcni.html
 
 
 www: $(HTML)
@@ -19,37 +24,37 @@
 	copy -v README.h $(WWW)/index.html
 
 clean:
-	rm -f *~ *.aux *.tex *.dvi *.log *.html *.toc
+	$(RM) *~ *.aux *.tex *.dvi *.log *.html *.toc
 
 clobber: clean
 
 compress.html: compress.nw
-	$(NOWEAVE) -filter l2h -index -autodefs c -html compress.nw > compress.html
+	$(NOWEAVE) -filter l2h -index -autodefs c -html $< > $@
 compress.tex: compress.nw
-	$(NOWEAVE) -index -autodefs c compress.nw > compress.tex
+	$(NOWEAVE) -index -autodefs c $< > $@
 dag.html: dag.nw
-	$(NOWEAVE) -filter l2h -index -autodefs icon -html dag.nw > dag.html
+	$(NOWEAVE) -filter l2h -index -autodefs icon -html $< > $@
 dag.tex: dag.nw
-	$(NOWEAVE) -index -autodefs icon dag.nw > dag.tex
+	$(NOWEAVE) -index -autodefs icon $< > $@
 mipscoder.html: mipscoder.nw
-	$(NOWEAVE) -filter l2h -index -autodefs sml -html mipscoder.nw > mipscoder.html
+	$(NOWEAVE) -filter l2h -index -autodefs sml -html $< > $@
 mipscoder.tex: mipscoder.nw
-	$(NOWEAVE) -autodefs sml -index mipscoder.nw > mipscoder.tex
+	$(NOWEAVE) -autodefs sml -index $< > $@
 scanner.html: scanner.nw
-	$(NOWEAVE) -filter l2h -index -autodefs c -autodefs yacc -html scanner.nw > scanner.html
+	$(NOWEAVE) -filter l2h -index -autodefs c -autodefs yacc -html $< > $@
 scanner.tex: scanner.nw
-	$(NOWEAVE) -index -autodefs c -autodefs yacc scanner.nw > scanner.tex
+	$(NOWEAVE) -index -autodefs c -autodefs yacc $< > $@
 tree.html: tree.nw
-	$(NOWEAVE) -filter l2h -index -autodefs icon -html tree.nw > tree.html
+	$(NOWEAVE) -filter l2h -index -autodefs icon -html $< > $@
 tree.tex: tree.nw
-	$(NOWEAVE) -index -autodefs icon tree.nw > tree.tex
+	$(NOWEAVE) -index -autodefs icon $< > $@
 test.html: test.nw
-	$(NOWEAVE) -filter l2h -html test.nw > test.html
+	$(NOWEAVE) -filter l2h -html $< > $@
 test.tex: test.nw
-	$(NOWEAVE) test.nw > test.tex
+	$(NOWEAVE) $< > $@
 wc.html: wc.nw2html
-	$(NOWEAVE) -autodefs c -filter btdefn -index -html -n wc.nw2html > wc.html
+	$(NOWEAVE) -autodefs c -filter btdefn -index -html -n $< > $@
 wcni.html: wc.nw2html
-	$(NOWEAVE) -filter btdefn -x     -html -n wc.nw2html > wcni.html
+	$(NOWEAVE) -filter btdefn -x     -html -n $< > $@
 wc.tex: wc.nw
-	$(NOWEAVE) -autodefs c -filter btdefn -index wc.nw > wc.tex
+	$(NOWEAVE) -autodefs c -filter btdefn -index $< > $@
diff --git a/examples/Makefile.awk b/examples/Makefile.awk
--- a/examples/Makefile.awk
+++ b/examples/Makefile.awk
@@ -4,14 +4,19 @@
 NOWEAVE=noweave
 
 .SUFFIXES: .i3 .m3 .nw .tex .dvi .html
-.nw.html: ;	$(NOWEAVE) -filter btdefn -index -html $*.nw > $*.html
-.nw.tex: ;	$(NOWEAVE) -index -filter btdefn $*.nw > $*.tex
-.nw.i3:	;	$(NOTANGLE) -Rinterface -L'<* LINE %L "%F" *>%N' $*.nw > $*.i3
-.nw.m3:	;	$(NOTANGLE) -L'<* LINE %L "%F" *>%N' $*.nw > $*.m3
-.tex.dvi: ;	latex '\scrollmode \input '"$*"; while grep -s 'Rerun to get cross-references right' $*.log; do latex '\scrollmode \input '"$*"; done
+.nw.html:
+	$(NOWEAVE) -filter btdefn -index -html $< > $@
+.nw.tex:
+	$(NOWEAVE) -index -filter btdefn $< > $@
+.nw.i3:
+	$(NOTANGLE) -Rinterface -L'<* LINE %L "%F" *>%N' $< > $@
+.nw.m3:
+	$(NOTANGLE) -L'<* LINE %L "%F" *>%N' $< > $@
+.tex.dvi:
+	latex '\scrollmode \input '"$*"; while grep -s 'Rerun to get cross-references right' $*.log; do latex '\scrollmode \input '"$*"; done
 
 HTML=breakmodel.html compress.html dag.html graphs.html mipscoder.html primes.html \
-     scanner.html test.html tree.html wc.html wcni.html
+	scanner.html test.html tree.html wc.html wcni.html
 DVI=compress.dvi dag.dvi mipscoder.dvi scanner.dvi tree.dvi test.dvi wc.dvi
 
 
@@ -22,37 +27,37 @@
 	copy -v README.h $(WWW)/index.html
 
 clean:
-	rm -f *~ *.aux *.tex *.dvi *.log *.html *.toc
+	$(RM) *~ *.aux *.tex *.dvi *.log *.html *.toc
 
 clobber: clean
 
 compress.html: compress.nw
-	$(NOWEAVE) -index -html compress.nw > compress.html
+	$(NOWEAVE) -index -html $< > $@
 compress.tex: compress.nw
-	$(NOWEAVE) -index compress.nw > compress.tex
+	$(NOWEAVE) -index $< > $@
 dag.html: dag.nw
-	$(NOWEAVE) -index -html dag.nw > dag.html
+	$(NOWEAVE) -index -html $< > $@
 dag.tex: dag.nw
-	$(NOWEAVE) -index dag.nw > dag.tex
+	$(NOWEAVE) -index $< > $@
 mipscoder.html: mipscoder.nw
-	$(NOWEAVE) -index -html mipscoder.nw > mipscoder.html
+	$(NOWEAVE) -index -html $< > $@
 mipscoder.tex: mipscoder.nw
-	$(NOWEAVE) -index mipscoder.nw > mipscoder.tex
+	$(NOWEAVE) -index $< > $@
 scanner.html: scanner.nw
-	$(NOWEAVE) -index -html scanner.nw > scanner.html
+	$(NOWEAVE) -index -html $< > $@
 scanner.tex: scanner.nw
-	$(NOWEAVE) -index scanner.nw > scanner.tex
+	$(NOWEAVE) -index $< > $@
 tree.html: tree.nw
-	$(NOWEAVE) -index -html tree.nw > tree.html
+	$(NOWEAVE) -index -html $< > $@
 tree.tex: tree.nw
-	$(NOWEAVE) -index tree.nw > tree.tex
+	$(NOWEAVE) -index $< > $@
 test.html: test.nw
-	$(NOWEAVE) -html test.nw > test.html
+	$(NOWEAVE) -html $< > $@
 test.tex: test.nw
-	$(NOWEAVE) test.nw > test.tex
+	$(NOWEAVE) $< > $@
 wc.html: wc.nw2html
-	$(NOWEAVE) -filter btdefn -index -html -n wc.nw2html > wc.html
+	$(NOWEAVE) -filter btdefn -index -html -n $< > $@
 wcni.html: wc.nw2html
-	$(NOWEAVE) -filter btdefn -x     -html -n wc.nw2html > wcni.html
+	$(NOWEAVE) -filter btdefn -x     -html -n $< > $@
 wc.tex: wc.nw
-	$(NOWEAVE) -filter btdefn -index wc.nw > wc.tex
+	$(NOWEAVE) -filter btdefn -index $< > $@
diff --git a/src/Makefile b/src/Makefile
--- a/src/Makefile
+++ b/src/Makefile
@@ -18,16 +18,17 @@
 # MAN7EXT is the extension for the nowebstyle man page (usually 7)
 # TEXINPUTS is the directory for TeX macro files
 # ELISP is the directory for emacs lisp files, or /dev/null not to install
-BIN=/usr/local/noweb
-LIB=/usr/local/noweb/lib
-MAN=/usr/local/noweb/man
+PREFIX=/usr/local
+BIN=$(PREFIX)/bin
+LIB=$(PREFIX)/libexec/noweb
+MAN=$(PREFIX)/share/man
 MANEXT=1
 MAN7EXT=7
-TEXINPUTS=/usr/local/tex/inputs
+TEXINPUTS=$(PREFIX)/tex/inputs
 ELISP=/dev/null
 
 # change WEAVE if you want a different version of noweave to be installed
-WEAVE=noweave		
+WEAVE=noweave
 
 # Stop editing.	 No user-serviceable parts below.
 SHELL=/bin/sh
@@ -37,186 +38,183 @@
 MAN7DIR=$(MAN)/man$(MAN7EXT)
 CATDIR=$(MAN)/cat$(MANEXT)
 CAT7DIR=$(MAN)/cat$(MAN7EXT)
-LIBNAME=$(LIB)
-TEXNAME=$(TEXINPUTS)
 
-all: 
-	cd c; make "CC=$(CC)" "CFLAGS=$(CFLAGS)" all 
-	for i in shell lib xdoc tex; do (cd $$i; make all); done
-	cd $(LIBSRC); make "ICONT=$(ICONT)" "ICONC=$(ICONC)" all
+all:
+	$(MAKE) -C c "CC=$(CC)" "CFLAGS=$(CFLAGS)" $@
+	for i in shell lib xdoc tex; do $(MAKE) -C $$i $@; done
+	$(MAKE) -C $(LIBSRC) "ICONT=$(ICONT)" "ICONC=$(ICONC)" $@
 
 FAQ: FAQ.html
-	sleep 1; html2ascii FAQ.html > FAQ
+	sleep 1; html2ascii $< > $@
 
 FAQ.html: $(HOME)/www/noweb/FAQ.html
-	rm -f FAQ.html
-	/bin/cp $(HOME)/www/noweb/FAQ.html FAQ.html
-	chmod -w FAQ.html
+	$(RM) $@
+	cp $< $@
+	chmod -w $@
 
 install: install-code install-man install-tex install-elisp
 uninstall: uninstall-code uninstall-man uninstall-tex uninstall-elisp
-	-rmdir $(BIN) $(LIB) 2>/dev/null || true
+	-rmdir $(DESTDIR)$(BIN) $(DESTDIR)$(LIB) 2>/dev/null || true
 
 install-shell:
-	mkdir -p $(BIN) $(LIB)
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noweb > $(BIN)/noweb
-	chmod +x $(BIN)/noweb
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/notangle > $(BIN)/notangle
-	chmod +x $(BIN)/notangle
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/$(WEAVE) > $(BIN)/$(WEAVE)
-	chmod +x $(BIN)/$(WEAVE)
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nountangle > $(BIN)/nountangle
-	chmod +x $(BIN)/nountangle
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nodefs > $(BIN)/nodefs
-	chmod +x $(BIN)/nodefs
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noroots > $(BIN)/noroots
-	chmod +x $(BIN)/noroots
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nuweb2noweb > $(BIN)/nuweb2noweb
-	chmod +x $(BIN)/nuweb2noweb
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/cpif > $(BIN)/cpif
-	chmod +x $(BIN)/cpif
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/htmltoc > $(BIN)/htmltoc
-	chmod +x $(BIN)/htmltoc
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noroff > $(BIN)/noroff
-	chmod +x $(BIN)/noroff
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/toroff > $(LIB)/toroff
-	chmod +x $(LIB)/toroff
-	cp shell/tmac.w $(LIB)
+	mkdir -p $(DESTDIR)$(BIN) $(DESTDIR)$(LIB)
+	sed "s@|LIBDIR|@$(LIB)@" shell/noweb > $(DESTDIR)$(BIN)/noweb
+	chmod +x $(DESTDIR)$(BIN)/noweb
+	sed "s@|LIBDIR|@$(LIB)@" shell/notangle > $(DESTDIR)$(BIN)/notangle
+	chmod +x $(DESTDIR)$(BIN)/notangle
+	sed "s@|LIBDIR|@$(LIB)@" shell/$(WEAVE) > $(DESTDIR)$(BIN)/$(WEAVE)
+	chmod +x $(DESTDIR)$(BIN)/$(WEAVE)
+	sed "s@|LIBDIR|@$(LIB)@" shell/nountangle > $(DESTDIR)$(BIN)/nountangle
+	chmod +x $(DESTDIR)$(BIN)/nountangle
+	sed "s@|LIBDIR|@$(LIB)@" shell/nodefs > $(DESTDIR)$(BIN)/nodefs
+	chmod +x $(DESTDIR)$(BIN)/nodefs
+	sed "s@|LIBDIR|@$(LIB)@" shell/noroots > $(DESTDIR)$(BIN)/noroots
+	chmod +x $(DESTDIR)$(BIN)/noroots
+	sed "s@|LIBDIR|@$(LIB)@" shell/nuweb2noweb > $(DESTDIR)$(BIN)/nuweb2noweb
+	chmod +x $(DESTDIR)$(BIN)/nuweb2noweb
+	sed "s@|LIBDIR|@$(LIB)@" shell/cpif > $(DESTDIR)$(BIN)/cpif
+	chmod +x $(DESTDIR)$(BIN)/cpif
+	sed "s@|LIBDIR|@$(LIB)@" shell/htmltoc > $(DESTDIR)$(BIN)/htmltoc
+	chmod +x $(DESTDIR)$(BIN)/htmltoc
+	sed "s@|LIBDIR|@$(LIB)@" shell/noroff > $(DESTDIR)$(BIN)/noroff
+	chmod +x $(DESTDIR)$(BIN)/noroff
+	sed "s@|LIBDIR|@$(LIB)@" shell/toroff > $(DESTDIR)$(LIB)/toroff
+	chmod +x $(DESTDIR)$(LIB)/toroff
+	cp shell/tmac.w $(DESTDIR)$(LIB)
 
 uninstall-shell:
-	rm -f $(BIN)/noweb
-	rm -f $(BIN)/notangle
-	rm -f $(BIN)/$(WEAVE)
-	rm -f $(BIN)/nountangle
-	rm -f $(BIN)/nodefs
-	rm -f $(BIN)/noroots
-	rm -f $(BIN)/nuweb2noweb
-	rm -f $(BIN)/cpif
-	rm -f $(BIN)/htmltoc
-	rm -f $(BIN)/noroff
-	rm -f $(LIB)/toroff
-	rm -f $(LIB)/tmac.w
+	$(RM) $(DESTDIR)$(BIN)/noweb
+	$(RM) $(DESTDIR)$(BIN)/notangle
+	$(RM) $(DESTDIR)$(BIN)/$(WEAVE)
+	$(RM) $(DESTDIR)$(BIN)/nountangle
+	$(RM) $(DESTDIR)$(BIN)/nodefs
+	$(RM) $(DESTDIR)$(BIN)/noroots
+	$(RM) $(DESTDIR)$(BIN)/nuweb2noweb
+	$(RM) $(DESTDIR)$(BIN)/cpif
+	$(RM) $(DESTDIR)$(BIN)/htmltoc
+	$(RM) $(DESTDIR)$(BIN)/noroff
+	$(RM) $(DESTDIR)$(LIB)/toroff
+	$(RM) $(DESTDIR)$(LIB)/tmac.w
 
 install-code: install-shell
-	mkdir -p $(BIN) $(LIB)
+	mkdir -p $(DESTDIR)$(BIN) $(DESTDIR)$(LIB)
 	strip c/nt c/markup c/mnt c/finduses c/nwmktemp
-	cp c/nt c/markup c/mnt c/finduses c/nwmktemp $(LIB)
-	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
-	cd lib; make LIB=$(LIB) install
+	cp c/nt c/markup c/mnt c/finduses c/nwmktemp $(DESTDIR)$(LIB)
+	$(MAKE) -C $(LIBSRC) ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
+	$(MAKE) -C lib LIB=$(LIB) install
 
 uninstall-code: uninstall-shell
-	rm -f $(LIB)/nt $(LIB)/markup $(LIB)/mnt $(LIB)/finduses 
-	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
-	cd lib; make LIB=$(LIB) uninstall
+	$(RM) $(DESTDIR)$(LIB)/nt $(DESTDIR)$(LIB)/markup $(DESTDIR)$(LIB)/mnt $(DESTDIR)$(LIB)/finduses $(DESTDIR)$(LIB)/nwmktemp
+	$(MAKE) -C $(LIBSRC) ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
+	$(MAKE) -C lib LIB=$(LIB) uninstall
 install-man:
-	mkdir -p $(MAN) $(MANDIR) $(MAN7DIR)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.1 > $(MANDIR)/cpif.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.1 > $(MANDIR)/nodefs.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.1 > $(MANDIR)/noroots.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.1 > $(MANDIR)/noweb.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.1 > $(MANDIR)/noindex.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.1 > $(MANDIR)/nuweb2noweb.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.1 > $(MANDIR)/notangle.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.1 > $(MANDIR)/noroff.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.1 > $(MANDIR)/sl2h.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.1 > $(MANDIR)/htmltoc.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.7 > $(MAN7DIR)/nowebstyle.$(MAN7EXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.7 > $(MAN7DIR)/nowebfilters.$(MAN7EXT)
-	rm -f $(MANDIR)/noweave.$(MANEXT)
-	(cd $(MANDIR); ln notangle.$(MANEXT) noweave.$(MANEXT))
-	rm -f $(MANDIR)/nountangle.$(MANEXT)
-	(cd $(MANDIR); ln notangle.$(MANEXT) nountangle.$(MANEXT))
+	mkdir -p $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/cpif.1 > $(DESTDIR)$(MANDIR)/cpif.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nodefs.1 > $(DESTDIR)$(MANDIR)/nodefs.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noroots.1 > $(DESTDIR)$(MANDIR)/noroots.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noweb.1 > $(DESTDIR)$(MANDIR)/noweb.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noindex.1 > $(DESTDIR)$(MANDIR)/noindex.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nuweb2noweb.1 > $(DESTDIR)$(MANDIR)/nuweb2noweb.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/notangle.1 > $(DESTDIR)$(MANDIR)/notangle.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noroff.1 > $(DESTDIR)$(MANDIR)/noroff.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/sl2h.1 > $(DESTDIR)$(MANDIR)/sl2h.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/htmltoc.1 > $(DESTDIR)$(MANDIR)/htmltoc.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nowebstyle.7 > $(DESTDIR)$(MAN7DIR)/nowebstyle.$(MAN7EXT)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nowebfilters.7 > $(DESTDIR)$(MAN7DIR)/nowebfilters.$(MAN7EXT)
+	$(RM) $(DESTDIR)$(MANDIR)/noweave.$(MANEXT)
+	(cd $(DESTDIR)$(MANDIR) && ln -s notangle.$(MANEXT) noweave.$(MANEXT))
+	$(RM) $(DESTDIR)$(MANDIR)/nountangle.$(MANEXT)
+	(cd $(DESTDIR)$(MANDIR) && ln -s notangle.$(MANEXT) nountangle.$(MANEXT))
 uninstall-man:
-	rm -f $(MANDIR)/cpif.$(MANEXT)
-	rm -f $(MANDIR)/nodefs.$(MANEXT)
-	rm -f $(MANDIR)/noroots.$(MANEXT)
-	rm -f $(MANDIR)/noweb.$(MANEXT)
-	rm -f $(MANDIR)/noindex.$(MANEXT)
-	rm -f $(MANDIR)/nuweb2noweb.$(MANEXT)
-	rm -f $(MANDIR)/notangle.$(MANEXT)
-	rm -f $(MANDIR)/noroff.$(MANEXT)
-	rm -f $(MANDIR)/sl2h.$(MANEXT)
-	rm -f $(MANDIR)/htmltoc.$(MANEXT)
-	rm -f $(MAN7DIR)/nowebstyle.$(MAN7EXT)
-	rm -f $(MAN7DIR)/nowebfilters.$(MAN7EXT)
-	rm -f $(MANDIR)/noweave.$(MANEXT)
-	rm -f $(MANDIR)/nountangle.$(MANEXT)
-	-rmdir $(MANDIR) $(MAN7DIR) $(MAN) 2>/dev/null || true
+	$(RM) $(DESTDIR)$(MANDIR)/cpif.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/nodefs.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/noroots.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/noweb.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/noindex.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/nuweb2noweb.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/notangle.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/noroff.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/sl2h.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/htmltoc.$(MANEXT)
+	$(RM) $(DESTDIR)$(MAN7DIR)/nowebstyle.$(MAN7EXT)
+	$(RM) $(DESTDIR)$(MAN7DIR)/nowebfilters.$(MAN7EXT)
+	$(RM) $(DESTDIR)$(MANDIR)/noweave.$(MANEXT)
+	$(RM) $(DESTDIR)$(MANDIR)/nountangle.$(MANEXT)
+	-rmdir $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR) $(DESTDIR)$(MAN) 2>/dev/null || true
 install-gzipped-man:
-	mkdir -p $(MAN) $(MANDIR) $(MAN7DIR)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.1  | gzip -9 > $(MANDIR)/cpif.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.1  | gzip -9 > $(MANDIR)/nodefs.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.1  | gzip -9 > $(MANDIR)/noroots.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.1  | gzip -9 > $(MANDIR)/noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.1  | gzip -9 > $(MANDIR)/noindex.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.1  | gzip -9 > $(MANDIR)/nuweb2noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.1  | gzip -9 > $(MANDIR)/notangle.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.1  | gzip -9 > $(MANDIR)/noroff.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.1  | gzip -9 > $(MANDIR)/sl2h.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.1  | gzip -9 > $(MANDIR)/htmltoc.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.7  | gzip -9 > $(MAN7DIR)/nowebstyle.$(MAN7EXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.7  | gzip -9 > $(MAN7DIR)/nowebfilters.$(MAN7EXT).gz
-	rm -f $(MANDIR)/noweave.$(MANEXT).gz
-	(cd $(MANDIR); ln notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
-	rm -f $(MANDIR)/nountangle.$(MANEXT).gz
-	(cd $(MANDIR); ln notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
+	mkdir -p $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/cpif.1  | gzip -9 > $(DESTDIR)$(MANDIR)/cpif.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nodefs.1  | gzip -9 > $(DESTDIR)$(MANDIR)/nodefs.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noroots.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noroots.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noweb.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noindex.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noindex.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nuweb2noweb.1  | gzip -9 > $(DESTDIR)$(MANDIR)/nuweb2noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/notangle.1  | gzip -9 > $(DESTDIR)$(MANDIR)/notangle.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noroff.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noroff.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/sl2h.1  | gzip -9 > $(DESTDIR)$(MANDIR)/sl2h.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/htmltoc.1  | gzip -9 > $(DESTDIR)$(MANDIR)/htmltoc.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nowebstyle.7  | gzip -9 > $(DESTDIR)$(MAN7DIR)/nowebstyle.$(MAN7EXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nowebfilters.7  | gzip -9 > $(DESTDIR)$(MAN7DIR)/nowebfilters.$(MAN7EXT).gz
+	$(RM) $(DESTDIR)$(MANDIR)/noweave.$(MANEXT).gz
+	(cd $(DESTDIR)$(MANDIR) && ln -s notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
+	$(RM) $(DESTDIR)$(MANDIR)/nountangle.$(MANEXT).gz
+	(cd $(DESTDIR)$(MANDIR) && ln -s notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
 install-preformat-man:
 	-echo "Warning: install-preformat-man is obsolete, even on Slackware systems" 1>&2
-	mkdir -p $(MAN) $(CATDIR) $(CAT7DIR)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.txt  | gzip > $(CATDIR)/cpif.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.txt  | gzip > $(CATDIR)/nodefs.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.txt  | gzip > $(CATDIR)/noroots.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.txt  | gzip > $(CATDIR)/noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.txt  | gzip > $(CATDIR)/noindex.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.txt  | gzip > $(CATDIR)/nuweb2noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.txt  | gzip > $(CATDIR)/notangle.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.txt  | gzip > $(CATDIR)/noroff.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.txt  | gzip > $(CATDIR)/sl2h.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.txt  | gzip > $(CATDIR)/htmltoc.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.txt  | gzip > $(CAT7DIR)/nowebstyle.$(MAN7EXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.txt  | gzip > $(CAT7DIR)/nowebfilters.$(MAN7EXT).gz
-	rm -f $(CATDIR)/noweave.$(MANEXT).gz
-	(cd $(CATDIR); ln notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
-	rm -f $(CATDIR)/nountangle.$(MANEXT).gz
-	(cd $(CATDIR); ln notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
+	mkdir -p $(DESTDIR)$(CATDIR) $(DESTDIR)$(CAT7DIR)
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/cpif.txt  | gzip > $(DESTDIR)$(CATDIR)/cpif.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nodefs.txt  | gzip > $(DESTDIR)$(CATDIR)/nodefs.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noroots.txt  | gzip > $(DESTDIR)$(CATDIR)/noroots.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noweb.txt  | gzip > $(DESTDIR)$(CATDIR)/noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noindex.txt  | gzip > $(DESTDIR)$(CATDIR)/noindex.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nuweb2noweb.txt  | gzip > $(DESTDIR)$(CATDIR)/nuweb2noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/notangle.txt  | gzip > $(DESTDIR)$(CATDIR)/notangle.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/noroff.txt  | gzip > $(DESTDIR)$(CATDIR)/noroff.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/sl2h.txt  | gzip > $(DESTDIR)$(CATDIR)/sl2h.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/htmltoc.txt  | gzip > $(DESTDIR)$(CATDIR)/htmltoc.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nowebstyle.txt  | gzip > $(DESTDIR)$(CAT7DIR)/nowebstyle.$(MAN7EXT).gz
+	sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@" xdoc/nowebfilters.txt  | gzip > $(DESTDIR)$(CAT7DIR)/nowebfilters.$(MAN7EXT).gz
+	$(RM) $(DESTDIR)$(CATDIR)/noweave.$(MANEXT).gz
+	(cd $(DESTDIR)$(CATDIR) && ln -s notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
+	$(RM) $(DESTDIR)$(CATDIR)/nountangle.$(MANEXT).gz
+	(cd $(DESTDIR)$(CATDIR) && ln -s notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
 install-tex:
-	mkdir -p $(TEXINPUTS)
-	cp tex/nwmac.tex tex/noweb.sty $(TEXINPUTS)
+	mkdir -p $(DESTDIR)$(TEXINPUTS)
+	cp tex/nwmac.tex tex/noweb.sty $(DESTDIR)$(TEXINPUTS)
 	-texhash || echo "Program texhash not found or failed"
 
 uninstall-tex:
-	rm -f $(TEXINPUTS)/nwmac.tex $(TEXINPUTS)/noweb.sty || true
+	$(RM) $(DESTDIR)$(TEXINPUTS)/nwmac.tex $(DESTDIR)$(TEXINPUTS)/noweb.sty || true
 
 install-elisp:
-	if [ "/dev/null" != "$(ELISP)" ]; then mkdir -p $(ELISP); fi
-	cp elisp/noweb-mode.el $(ELISP)
+	if [ "/dev/null" != "$(ELISP)" ]; then mkdir -p $(DESTDIR)$(ELISP) && cp elisp/noweb-mode.el $(DESTDIR)$(ELISP); fi
 
 uninstall-elisp:
-	rm -f $(ELISP)/noweb-mode.el || true
+	if [ "/dev/null" != "$(ELISP)" ]; then $(RM) $(DESTDIR)$(ELISP)/noweb-mode.el; fi
 checkin:
-	for i in lib tex xdoc; do (cd $$i; make "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" checkin); done
-	for i in c icon awk; do (cd $$i; ci -l $(CINAME) $(CIMSG) *.nw Makefile); done
-	(cd elisp; ci -l $(CINAME) $(CIMSG) *.el)
+	for i in lib tex xdoc; do $(MAKE) -C $$i "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" $@; done
+	for i in c icon awk; do (cd $$i && ci -l $(CINAME) $(CIMSG) *.nw Makefile); done
+	(cd elisp && ci -l $(CINAME) $(CIMSG) *.el)
 	ci -l $(CINAME) $(CIMSG) Makefile.nw INSTALL INSTALL.DOS README FAQ COPYRIGHT nwmake *.nw
 
 source: FAQ
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make CPIF=">" source); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i CPIF=">" $@; done
 	sleep 1
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make touch); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i touch; done
 touch:
 	touch FAQ
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make touch); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 boot:
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make boot); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 clean:
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make clean); done
-	rm -f nwsrcfilter *~ */*~
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
+	$(RM) nwsrcfilter *~ */*~
 
 clobber: clean
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make clobber); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 
 Makefile: Makefile.nw
-	chmod +w Makefile
-	notangle -R'script' Makefile.nw | sh > Makefile
-	chmod -w Makefile
+	chmod +w $@
+	notangle -R'script' $< | sh > $@
+	chmod -w $@
 
diff --git a/src/Makefile.nw b/src/Makefile.nw
--- a/src/Makefile.nw
+++ b/src/Makefile.nw
@@ -23,16 +23,17 @@
 # MAN7EXT is the extension for the nowebstyle man page (usually 7)
 # TEXINPUTS is the directory for TeX macro files
 # ELISP is the directory for emacs lisp files, or /dev/null not to install
-BIN=/usr/local/noweb
-LIB=/usr/local/noweb/lib
-MAN=/usr/local/noweb/man
+PREFIX=/usr/local
+BIN=$(PREFIX)/bin
+LIB=$(PREFIX)/libexec/noweb
+MAN=$(PREFIX)/share/man
 MANEXT=1
 MAN7EXT=7
-TEXINPUTS=/usr/local/tex/inputs
+TEXINPUTS=$(PREFIX)/tex/inputs
 ELISP=/dev/null
 
 # change WEAVE if you want a different version of noweave to be installed
-WEAVE=noweave		
+WEAVE=noweave
 
 # Stop editing.	 No user-serviceable parts below.
 SHELL=/bin/sh
@@ -42,46 +43,44 @@
 MAN7DIR=$(MAN)/man$(MAN7EXT)
 CATDIR=$(MAN)/cat$(MANEXT)
 CAT7DIR=$(MAN)/cat$(MAN7EXT)
-LIBNAME=$(LIB)
-TEXNAME=$(TEXINPUTS)
 
-all: 
-	cd c; make "CC=$(CC)" "CFLAGS=$(CFLAGS)" all 
-	for i in shell lib xdoc tex; do (cd $$i; make all); done
-	cd $(LIBSRC); make "ICONT=$(ICONT)" "ICONC=$(ICONC)" all
+all:
+	$(MAKE) -C c "CC=$(CC)" "CFLAGS=$(CFLAGS)" $@
+	for i in shell lib xdoc tex; do $(MAKE) -C $$i $@; done
+	$(MAKE) -C $(LIBSRC) "ICONT=$(ICONT)" "ICONC=$(ICONC)" $@
 
 FAQ: FAQ.html
-	sleep 1; html2ascii FAQ.html > FAQ
+	sleep 1; html2ascii $< > $@
 
 FAQ.html: $(HOME)/www/noweb/FAQ.html
-	rm -f FAQ.html
-	/bin/cp $(HOME)/www/noweb/FAQ.html FAQ.html
-	chmod -w FAQ.html
+	$(RM) $@
+	cp $< $@
+	chmod -w $@
 
 install: install-code install-man install-tex install-elisp
 uninstall: uninstall-code uninstall-man uninstall-tex uninstall-elisp
-	-rmdir $(BIN) $(LIB) 2>/dev/null || true
+	-rmdir $(DESTDIR)$(BIN) $(DESTDIR)$(LIB) 2>/dev/null || true
 
 install-shell:
-	mkdir -p $(BIN) $(LIB)
+	mkdir -p $(DESTDIR)$(BIN) $(DESTDIR)$(LIB)
 	<<shell binaries>>
-	cp shell/tmac.w $(LIB)
+	cp shell/tmac.w $(DESTDIR)$(LIB)
 
 uninstall-shell:
 	<<uninstall shell binaries>>
-	rm -f $(LIB)/tmac.w
+	$(RM) $(DESTDIR)$(LIB)/tmac.w
 
 install-code: install-shell
-	mkdir -p $(BIN) $(LIB)
+	mkdir -p $(DESTDIR)$(BIN) $(DESTDIR)$(LIB)
 	strip c/nt c/markup c/mnt c/finduses c/nwmktemp
-	cp c/nt c/markup c/mnt c/finduses c/nwmktemp $(LIB)
-	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
-	cd lib; make LIB=$(LIB) install
+	cp c/nt c/markup c/mnt c/finduses c/nwmktemp $(DESTDIR)$(LIB)
+	$(MAKE) -C $(LIBSRC) ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
+	$(MAKE) -C lib LIB=$(LIB) install
 
 uninstall-code: uninstall-shell
-	rm -f $(LIB)/nt $(LIB)/markup $(LIB)/mnt $(LIB)/finduses 
-	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
-	cd lib; make LIB=$(LIB) uninstall
+	$(RM) $(DESTDIR)$(LIB)/nt $(DESTDIR)$(LIB)/markup $(DESTDIR)$(LIB)/mnt $(DESTDIR)$(LIB)/finduses $(DESTDIR)$(LIB)/nwmktemp
+	$(MAKE) -C $(LIBSRC) ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
+	$(MAKE) -C lib LIB=$(LIB) uninstall
 @ I do the [[<<shell binaries>>]] before [[$(LIBSRC)]] so that the
 Icon version of [[htmltoc]], if present, will overwrite the Perl
 version.
@@ -91,37 +90,37 @@
 	 noroff
 do
   echo '@<<shell binaries@>>='
-  echo 'sed "s@|LIBDIR|@$(LIBNAME)@"' "shell/$i" '> $(BIN)/'"$i"
-  echo 'chmod +x $(BIN)/'"$i"
+  echo 'sed "s@|LIBDIR|@$(LIB)@"' "shell/$i" '> $(DESTDIR)$(BIN)/'"$i"
+  echo 'chmod +x $(DESTDIR)$(BIN)/'"$i"
   echo '@<<uninstall shell binaries@>>='
-  echo 'rm -f $(BIN)/'"$i"
+  echo '$(RM) $(DESTDIR)$(BIN)/'"$i"
 done
 for i in toroff
 do
   echo '@<<shell binaries@>>='
-  echo 'sed "s@|LIBDIR|@$(LIBNAME)@"' "shell/$i" '> $(LIB)/'"$i"
-  echo 'chmod +x $(LIB)/'"$i"
+  echo 'sed "s@|LIBDIR|@$(LIB)@"' "shell/$i" '> $(DESTDIR)$(LIB)/'"$i"
+  echo 'chmod +x $(DESTDIR)$(LIB)/'"$i"
   echo '@<<uninstall shell binaries@>>='
-  echo 'rm -f $(LIB)/'"$i"
+  echo '$(RM) $(DESTDIR)$(LIB)/'"$i"
 done
 <<*>>=
 install-man:
-	mkdir -p $(MAN) $(MANDIR) $(MAN7DIR)
+	mkdir -p $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR)
 	<<ordinary pages>>
 uninstall-man:
 	<<uninstall ordinary pages>>
-	-rmdir $(MANDIR) $(MAN7DIR) $(MAN) 2>/dev/null || true
-@ 
+	-rmdir $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR) $(DESTDIR)$(MAN) 2>/dev/null || true
+@
 Slackware no longer uses preformatted compressed pages, just
 compressed pages.
 <<*>>=
 install-gzipped-man:
-	mkdir -p $(MAN) $(MANDIR) $(MAN7DIR)
+	mkdir -p $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR)
 	<<compressed pages>>
 <<*>>=
 install-preformat-man:
 	-echo "Warning: install-preformat-man is obsolete, even on Slackware systems" 1>&2
-	mkdir -p $(MAN) $(CATDIR) $(CAT7DIR)
+	mkdir -p $(DESTDIR)$(CATDIR) $(DESTDIR)$(CAT7DIR)
 	<<preformatted compressed pages>>
 <<generate chunks>>=
 NORMALPAGES="cpif nodefs noroots noweb noindex nuweb2noweb notangle noroff sl2h htmltoc"
@@ -131,98 +130,97 @@
 
 for i in $NORMALPAGES; do
   echo '@<<ordinary pages@>>='
-  echo 'sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@"' \
-	"xdoc/$i.1" '> $(MANDIR)/'"$i"'.$(MANEXT)'
+  echo 'sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@"' \
+	"xdoc/$i.1" '> $(DESTDIR)$(MANDIR)/'"$i"'.$(MANEXT)'
   echo '@<<uninstall ordinary pages@>>='
-  echo 'rm -f $(MANDIR)/'"$i"'.$(MANEXT)'
+  echo '$(RM) $(DESTDIR)$(MANDIR)/'"$i"'.$(MANEXT)'
 done
 for i in $NORMAL7PAGES; do
   echo '@<<ordinary pages@>>='
-  echo 'sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@"' \
-	"xdoc/$i.7" '> $(MAN7DIR)/'"$i"'.$(MAN7EXT)'
+  echo 'sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@"' \
+	"xdoc/$i.7" '> $(DESTDIR)$(MAN7DIR)/'"$i"'.$(MAN7EXT)'
   echo '@<<uninstall ordinary pages@>>='
-  echo 'rm -f $(MAN7DIR)/'"$i"'.$(MAN7EXT)'
+  echo '$(RM) $(DESTDIR)$(MAN7DIR)/'"$i"'.$(MAN7EXT)'
 done
 
 for i in $LINKPAGES; do
   echo '@<<ordinary pages@>>='
-  echo 'rm -f $(MANDIR)/'"$i"'.$(MANEXT)'
-  echo '(cd $(MANDIR); ln notangle.$(MANEXT)' "$i"'.$(MANEXT))'
+  echo '$(RM) $(DESTDIR)$(MANDIR)/'"$i"'.$(MANEXT)'
+  echo '(cd $(DESTDIR)$(MANDIR) && ln -s notangle.$(MANEXT)' "$i"'.$(MANEXT))'
   echo '@<<uninstall ordinary pages@>>='
-  echo 'rm -f $(MANDIR)/'"$i"'.$(MANEXT)'
+  echo '$(RM) $(DESTDIR)$(MANDIR)/'"$i"'.$(MANEXT)'
 done
 
 echo '@<<compressed pages@>>='
 
 for i in $NORMALPAGES; do
-  echo 'sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@"' \
-	"xdoc/$i.1" ' | gzip -9 > $(MANDIR)/'"$i"'.$(MANEXT).gz'
+  echo 'sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@"' \
+	"xdoc/$i.1" ' | gzip -9 > $(DESTDIR)$(MANDIR)/'"$i"'.$(MANEXT).gz'
 done
 for i in $NORMAL7PAGES; do
-  echo 'sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@"' \
-	"xdoc/$i.7" ' | gzip -9 > $(MAN7DIR)/'"$i"'.$(MAN7EXT).gz'
+  echo 'sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@"' \
+	"xdoc/$i.7" ' | gzip -9 > $(DESTDIR)$(MAN7DIR)/'"$i"'.$(MAN7EXT).gz'
 done
 
 for i in $LINKPAGES; do
-  echo 'rm -f $(MANDIR)/'"$i"'.$(MANEXT).gz'
-  echo '(cd $(MANDIR); ln notangle.$(MANEXT).gz' "$i"'.$(MANEXT).gz)'
+  echo '$(RM) $(DESTDIR)$(MANDIR)/'"$i"'.$(MANEXT).gz'
+  echo '(cd $(DESTDIR)$(MANDIR) && ln -s notangle.$(MANEXT).gz' "$i"'.$(MANEXT).gz)'
 done
 
 echo '@<<preformatted compressed pages@>>='
 
 for i in $NORMALPAGES; do
-  echo 'sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@"' \
-	"xdoc/$i.txt" ' | gzip > $(CATDIR)/'"$i"'.$(MANEXT).gz'
+  echo 'sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@"' \
+	"xdoc/$i.txt" ' | gzip > $(DESTDIR)$(CATDIR)/'"$i"'.$(MANEXT).gz'
 done
 for i in $NORMAL7PAGES; do
-  echo 'sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@"' \
-	"xdoc/$i.txt" ' | gzip > $(CAT7DIR)/'"$i"'.$(MAN7EXT).gz'
+  echo 'sed -e "s@|LIBDIR|@$(LIB)@" -e "s@|TEXINPUTS|@$(TEXINPUTS)@"' \
+	"xdoc/$i.txt" ' | gzip > $(DESTDIR)$(CAT7DIR)/'"$i"'.$(MAN7EXT).gz'
 done
 
 for i in $LINKPAGES; do
-  echo 'rm -f $(CATDIR)/'"$i"'.$(MANEXT).gz'
-  echo '(cd $(CATDIR); ln notangle.$(MANEXT).gz' "$i"'.$(MANEXT).gz)'
+  echo '$(RM) $(DESTDIR)$(CATDIR)/'"$i"'.$(MANEXT).gz'
+  echo '(cd $(DESTDIR)$(CATDIR) && ln -s notangle.$(MANEXT).gz' "$i"'.$(MANEXT).gz)'
 done
 <<*>>=
 install-tex:
-	mkdir -p $(TEXINPUTS)
-	cp tex/nwmac.tex tex/noweb.sty $(TEXINPUTS)
+	mkdir -p $(DESTDIR)$(TEXINPUTS)
+	cp tex/nwmac.tex tex/noweb.sty $(DESTDIR)$(TEXINPUTS)
 	-texhash || echo "Program texhash not found or failed"
 
 uninstall-tex:
-	rm -f $(TEXINPUTS)/nwmac.tex $(TEXINPUTS)/noweb.sty || true
+	$(RM) $(DESTDIR)$(TEXINPUTS)/nwmac.tex $(DESTDIR)$(TEXINPUTS)/noweb.sty || true
 
 install-elisp:
-	if [ "/dev/null" != "$(ELISP)" ]; then mkdir -p $(ELISP); fi
-	cp elisp/noweb-mode.el $(ELISP)
+	if [ "/dev/null" != "$(ELISP)" ]; then mkdir -p $(DESTDIR)$(ELISP) && cp elisp/noweb-mode.el $(DESTDIR)$(ELISP); fi
 
 uninstall-elisp:
-	rm -f $(ELISP)/noweb-mode.el || true
-@ 
+	if [ "/dev/null" != "$(ELISP)" ]; then $(RM) $(DESTDIR)$(ELISP)/noweb-mode.el; fi
+@
 <<*>>=
 checkin:
-	for i in lib tex xdoc; do (cd $$i; make "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" checkin); done
-	for i in c icon awk; do (cd $$i; ci -l $(CINAME) $(CIMSG) *.nw Makefile); done
-	(cd elisp; ci -l $(CINAME) $(CIMSG) *.el)
+	for i in lib tex xdoc; do $(MAKE) -C $$i "CINAME=$(CINAME)" "CIMSG=$(CIMSG)" $@; done
+	for i in c icon awk; do (cd $$i && ci -l $(CINAME) $(CIMSG) *.nw Makefile); done
+	(cd elisp && ci -l $(CINAME) $(CIMSG) *.el)
 	ci -l $(CINAME) $(CIMSG) Makefile.nw INSTALL INSTALL.DOS README FAQ COPYRIGHT nwmake *.nw
 
 source: FAQ
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make CPIF=">" source); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i CPIF=">" $@; done
 	sleep 1
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make touch); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i touch; done
 touch:
 	touch FAQ
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make touch); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 boot:
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make boot); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 clean:
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make clean); done
-	rm -f nwsrcfilter *~ */*~
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
+	$(RM) nwsrcfilter *~ */*~
 
 clobber: clean
-	for i in c shell lib xdoc icon awk tex; do (cd $$i; make clobber); done
+	for i in c shell lib xdoc icon awk tex; do $(MAKE) -C $$i $@; done
 
 Makefile: Makefile.nw
-	chmod +w Makefile
-	notangle -R'script' Makefile.nw | sh > Makefile
-	chmod -w Makefile
+	chmod +w $@
+	notangle -R'script' $< | sh > $@
+	chmod -w $@
diff --git a/src/awk/Makefile b/src/awk/Makefile
--- a/src/awk/Makefile
+++ b/src/awk/Makefile
@@ -8,11 +8,10 @@
 LIBEXECSBARE=noidx tohtml
 LIBEXECSDEP=totex
 LIBEXECS=$(LIBEXECSBARE) $(LIBEXECSDEP)
-BINEXECS=noindex 
+BINEXECS=noindex
 EXECS=$(BINEXECS) $(LIBEXECS)
 
-all:	$(EXECS)
-	chmod +x $(EXECS)
+all: $(EXECS)
 sources: $(EXECS)
 touch: $(EXECS)
 	touch $(EXECS)
@@ -20,28 +19,33 @@
 	touch $(EXECS)
 
 install: all
-	cp $(LIBEXECSBARE) $(LIB)
-	for i in $(LIBEXECSDEP); do sed "s@|LIBDIR|@$(LIB)@" "$$i" > $(LIB)/"$$i"; chmod +x $(LIB)/$$i; done
-	cp $(BINEXECS) $(BIN)
+	cp $(LIBEXECSBARE) $(DESTDIR)$(LIB)
+	for i in $(LIBEXECSDEP); do sed "s@|LIBDIR|@$(LIB)@" "$$i" > $(DESTDIR)$(LIB)/"$$i"; chmod +x $(DESTDIR)$(LIB)/$$i; done
+	cp $(BINEXECS) $(DESTDIR)$(BIN)
 
 uninstall:
-	for i in $(LIBEXECS); do rm -f $(LIB)/$$i; done
-	for i in $(BINEXECS); do rm -f $(BIN)/$$i; done
+	for i in $(LIBEXECS); do $(RM) $(DESTDIR)$(LIB)/$$i; done
+	for i in $(BINEXECS); do $(RM) $(DESTDIR)$(BIN)/$$i; done
 
 source: $(EXECS)
 
 totex: totex.nw
-	notangle -Rtotex totex.nw > totex
+	notangle -R$@ $< > $@
+	chmod +x $@
 
 noidx: noidx.nw
-	notangle noidx.nw > noidx
+	notangle $< > $@
+	chmod +x $@
 
 tohtml: tohtml.nw
-	notangle tohtml.nw > tohtml
+	notangle $< > $@
+	chmod +x $@
 
-noindex: noindex.nw 
-	notangle -Rnoindex noindex.nw > noindex
+noindex: noindex.nw
+	notangle -R$@ $< > $@
+	chmod +x $@
 
-clean: ;	rm -f *.log *.blg *.dvi *.toc *.aux *.tex *~ *.html
+clean:
+	$(RM) *.log *.blg *.dvi *.toc *.aux *.tex *~ *.html
 clobber: clean
-	rm -f totex noidx tohtml noindex
+	$(RM) totex noidx tohtml noindex
diff --git a/src/c/Makefile b/src/c/Makefile
--- a/src/c/Makefile
+++ b/src/c/Makefile
@@ -14,9 +14,9 @@
 	main.o errors.o columns.o
 MARKUPOBJS=markmain.o strsave.o markup.o errors.o getline.o columns.o
 FILES=markmain.nw markup.nw \
-      main.nw notangle.nw match.nw mnt.nw modules.nw modtrees.nw \
-      finduses.nw recognize.nw \
-      getline.nw columns.nw errors.nw strsave.nw 
+	main.nw notangle.nw match.nw mnt.nw modules.nw modtrees.nw \
+	finduses.nw recognize.nw \
+	getline.nw columns.nw errors.nw strsave.nw
 
 SRCS=columns.h errors.h getline.h markup.h match.h modtrees.h \
 	modules.h notangle.h recognize.h strsave.h \
@@ -32,81 +32,78 @@
 CPIF=>
 
 .SUFFIXES: .nw .tex .dvi .h
-.nw.tex: ;	noweave $*.nw >$*.tex
-.nw.c: ;	$(NOTANGLE) -L $*.nw >$*.c
-.nw.o: ;	$(NOTANGLE) -L $*.nw >$*.c
-		$(CC) $(CFLAGS) -c $*.c
-.nw.h: ;	$(NOTANGLE) -Rheader $*.nw $(CPIF) $*.h
+.nw.tex:
+	noweave $< >$@
+.nw.c:
+	$(NOTANGLE) -L $< >$@
+.nw.h:
+	$(NOTANGLE) -Rheader $< $(CPIF) $@
 
-all:	nt markup mnt finduses nwmktemp
+all: nt markup mnt finduses nwmktemp
 
-nt:	$(TANGLEOBJS)
-	$(CC) $(CFLAGS) -o nt $(TANGLEOBJS)
+nt: $(TANGLEOBJS)
+	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
 
 nwmktemp: nwmktemp.o
-	$(CC) $(CFLAGS) -o nwmktemp nwmktemp.o
+finduses: $(FINDUSESOBJS)
+markup: $(MARKUPOBJS)
+mnt: $(MNTOBJS)
 
-finduses:	$(FINDUSESOBJS)
-	$(CC) $(CFLAGS) -o finduses $(FINDUSESOBJS)
-
-markup:	$(MARKUPOBJS)
-	$(CC) $(CFLAGS) -o markup $(MARKUPOBJS)
-
-mnt:	$(MNTOBJS)
-	$(CC) $(CFLAGS) -o mnt $(MNTOBJS)
-
-source:	$(SRCS)
+source: $(SRCS)
 touch: $(SRCS)
 	touch $(SRCS)
 
-boot: ;	touch $(SRCS)
+boot:
+	touch $(SRCS)
 
-clean: ;	rm -f nt markup mnt finduses fakepretty
-		rm -f core *.makelog *.tex *.log *.blg *.dvi *.o *.toc *~ 
-		rm -f *.atac *.trace *.html
+clean:
+	$(RM) nt markup mnt finduses fakepretty
+	$(RM) core *.makelog *.tex *.log *.blg *.dvi *.o *.toc *~
+	$(RM) *.atac *.trace *.html
 
-clobber:	clean
-		rm -f $(SRCS) fakepretty.c pretty.[ch]
+clobber: clean
+	$(RM) $(SRCS) fakepretty.c pretty.[ch]
 
-checkin:	$(FILES) doc.nw
-		ci $(CINAME) $(CIMSG) -l $(FILES) doc.nw
+checkin: $(FILES) doc.nw
+	ci $(CINAME) $(CIMSG) -l $(FILES) doc.nw
 
-doc.tex:	doc.nw
-	cp doc.nw doc.tex
+doc.tex: doc.nw
+	cp $< $@
 
 allcode.tex: $(FILES)
-	noweave -n -index $(FILES) > allcode.tex
+	noweave -n -index $^ > $@
 
-doc.dvi:	doc.tex allcode.tex
-	latex doc; latex doc; latex doc
+doc.dvi: doc.tex allcode.tex
+	latex doc
+	latex doc
+	latex doc
 
 doc.ps: doc.dvi
 	dvips doc
 
 markup.ps: markmain.nw
-	notangle -Rmarkup.dot markmain.nw | dot -Tps > markup.ps
+	notangle -Rmarkup.dot $< | dot -Tps > $@
 
 FPOBJS=fakepretty.o pretty.o errors.o getline.o match.o strsave.o columns.o
 
 fakepretty.o: pretty.h
 
 fakepretty: $(FPOBJS)
-	$(CC) $(CFLAGS) -o fakepretty $(FPOBJS)
 
 
-columns.o:       columns.h 
-errors.o:        errors.h 
-finduses.o:     errors.h match.h getline.h recognize.h 
-getline.o:      columns.h errors.h getline.h 
+columns.o:      columns.h
+errors.o:       errors.h
+finduses.o:     errors.h match.h getline.h recognize.h
+getline.o:      columns.h errors.h getline.h
 main.o:         notangle.h errors.h columns.h modules.h modtrees.h
-markmain.o:     errors.h markup.h getline.h columns.h 
-markup.o:       markup.h strsave.h errors.h 
-match.o:        match.h 
-mnt.o:          modules.h modtrees.h notangle.h errors.h columns.h strsave.h 
-modtrees.o:     strsave.h modules.h modtrees.h errors.h 
-modules.o:      modules.h modtrees.h errors.h columns.h strsave.h 
-notangle.o:     strsave.h getline.h modules.h modtrees.h errors.h match.h notangle.h 
+markmain.o:     errors.h markup.h getline.h columns.h
+markup.o:       markup.h strsave.h errors.h
+match.o:        match.h
+mnt.o:          modules.h modtrees.h notangle.h errors.h columns.h strsave.h
+modtrees.o:     strsave.h modules.h modtrees.h errors.h
+modules.o:      modules.h modtrees.h errors.h columns.h strsave.h
+notangle.o:     strsave.h getline.h modules.h modtrees.h errors.h match.h notangle.h
 nwmktemp.o:
-pretty.o:	getline.h match.h errors.h pretty.h strsave.h 
-recognize.o:    
-strsave.o:      strsave.h errors.h 
+pretty.o:       getline.h match.h errors.h pretty.h strsave.h
+recognize.o:
+strsave.o:      strsave.h errors.h
diff --git a/src/icon/Makefile b/src/icon/Makefile
--- a/src/icon/Makefile
+++ b/src/icon/Makefile
@@ -6,23 +6,23 @@
 CPIF=| cpif		# change to ">" to insure all sources always made
 
 LIBEXECS=totex disambiguate noidx tohtml elide l2h docs2comments \
-       autodefs.tex autodefs.icon autodefs.yacc autodefs.sml autodefs.pascal \
+	autodefs.tex autodefs.icon autodefs.yacc autodefs.sml autodefs.pascal \
 	autodefs.promela autodefs.lrtl autodefs.asdl autodefs.mmix xchunks pipedocs
 LIBSPECIAL=autodefs.cee
 BINEXECS=noindex sl2h htmltoc
 EXECS=$(LIBEXECS) $(BINEXECS) $(LIBSPECIAL) pdcached
 SRCS=totex.icn disambiguate.icn noidx.icn texdefs.icn icondefs.icn \
-        yaccdefs.icn noindex.icn smldefs.icn tohtml.icn cdefs.icn elide.icn \
+	yaccdefs.icn noindex.icn smldefs.icn tohtml.icn cdefs.icn elide.icn \
 	l2h.icn sl2h.icn pascaldefs.icn promeladefs.icn lrtldefs.icn asdldefs.icn \
 	mmixdefs.icn htmltoc.icn xchunks.icn docs2comments.icn pipedocs.icn pdcached.icn
 
 .SUFFIXES: .nw .icn .html .tex .dvi
 .nw.icn:
-	notangle -L'#line %-1L "%F"%N' $*.nw $(CPIF) $*.icn
+	notangle -L'#line %-1L "%F"%N' $< $(CPIF) $@
 .nw.html:
-	noweave -filter l2h -autodefs icon -html -index $*.nw | htmltoc > $*.html
+	noweave -filter l2h -autodefs icon -html -index $< | htmltoc > $@
 .nw.tex:
-	noweave -delay -autodefs icon -index $*.nw > $*.tex
+	noweave -delay -autodefs icon -index $< > $@
 .tex.dvi:
 	latex $*; while grep -s 'Rerun to get cross' $*.log; do latex $*; done
 
@@ -34,118 +34,118 @@
 boot:
 	touch $(SRCS)
 
-install: $(EXECS)
-	cp $(LIBEXECS) $(LIB)
-	cp $(BINEXECS) $(BIN)
-	cp $(LIBSPECIAL) $(LIB)/autodefs.c
+install: all
+	cp $(LIBEXECS) $(DESTDIR)$(LIB)
+	cp $(BINEXECS) $(DESTDIR)$(BIN)
+	cp $(LIBSPECIAL) $(DESTDIR)$(LIB)/autodefs.c
 
 uninstall:
-	for i in $(LIBEXECS); do rm -f $(LIB)/$$i; done
-	for i in $(BINEXECS); do rm -f $(BIN)/$$i; done
-	rm -f $(LIB)/autodefs.c
+	for i in $(LIBEXECS); do $(RM) $(DESTDIR)$(LIB)/$$i; done
+	for i in $(BINEXECS); do $(RM) $(DESTDIR)$(BIN)/$$i; done
+	$(RM) $(DESTDIR)$(LIB)/autodefs.c
 
 clean:
-	/bin/rm -f *.tex *.dvi *.aux *.log *.blg *.bbl *~  *.toc *.html *.u1 *.u2 
-	/bin/rm -f *.[ch] *.ps *.gz
-	/bin/rm -f $(EXECS)
-	/bin/rm -f sl2h
+	$(RM) *.tex *.dvi *.aux *.log *.blg *.bbl *~  *.toc *.html *.u1 *.u2
+	$(RM) *.[ch] *.ps *.gz
+	$(RM) $(EXECS)
+	$(RM) sl2h
 
 clobber: clean
-	/bin/rm -f *.icn
+	$(RM) *.icn
 
 texdefs.icn: texdefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' texdefs.nw defns.nw $(CPIF) texdefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 icondefs.icn: icondefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' icondefs.nw defns.nw $(CPIF) icondefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 yaccdefs.icn: yaccdefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' yaccdefs.nw defns.nw $(CPIF) yaccdefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 smldefs.icn: smldefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' smldefs.nw defns.nw $(CPIF) smldefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 cdefs.icn: cdefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' cdefs.nw defns.nw $(CPIF) cdefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 pascaldefs.icn: pascaldefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' pascaldefs.nw defns.nw $(CPIF) pascaldefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 promeladefs.icn: promeladefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' promeladefs.nw defns.nw $(CPIF) promeladefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 lrtldefs.icn: lrtldefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' lrtldefs.nw defns.nw $(CPIF) lrtldefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 asdldefs.icn: asdldefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' asdldefs.nw defns.nw $(CPIF) asdldefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 mmixdefs.icn: mmixdefs.nw defns.nw
-	notangle -L'#line %-1L "%F"%N' mmixdefs.nw defns.nw $(CPIF) mmixdefs.icn
+	notangle -L'#line %-1L "%F"%N' $^ $(CPIF) $@
 
 autodefs.tex: texdefs.icn
-	$(ICONT) -o autodefs.tex texdefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.icon: icondefs.icn
-	$(ICONC) -o autodefs.icon icondefs.icn
+	$(ICONC) -o $@ $<
 
 autodefs.yacc: yaccdefs.icn
-	$(ICONT) -o autodefs.yacc yaccdefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.sml: smldefs.icn
-	$(ICONT) -o autodefs.sml smldefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.cee: cdefs.icn
-	$(ICONT) -o autodefs.cee cdefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.pascal: pascaldefs.icn
-	$(ICONT) -o autodefs.pascal pascaldefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.promela: promeladefs.icn
-	$(ICONT) -o autodefs.promela promeladefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.lrtl: lrtldefs.icn
-	$(ICONT) -o autodefs.lrtl lrtldefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.asdl: asdldefs.icn
-	$(ICONT) -o autodefs.asdl asdldefs.icn
+	$(ICONT) -o $@ $<
 
 autodefs.mmix: mmixdefs.icn
-	$(ICONT) -o autodefs.mmix mmixdefs.icn
+	$(ICONT) -o $@ $<
 
 totex: totex.icn
-	$(ICONC) totex.icn
+	$(ICONC) $<
 
 totexnr: totexnr.icn
-	$(ICONT) totexnr.icn
+	$(ICONT) $<
 
 tohtml: tohtml.icn
-	$(ICONC) tohtml.icn
+	$(ICONC) $<
 
 docs2comments: docs2comments.icn
-	$(ICONT) docs2comments.icn  # no longer compiles with iconc
+	$(ICONT) $<  # no longer compiles with iconc
 
 xchunks: xchunks.icn
-	$(ICONT) xchunks.icn
+	$(ICONT) $<
 
 l2h.icn: l2h.nw
-	notangle -L'#line %-1L "%F"%N' -R'l2h.icn' l2h.nw $(CPIF) l2h.icn
+	notangle -L'#line %-1L "%F"%N' -R$@ $< $(CPIF) $@
 l2h: l2h.icn
-	$(ICONT) -o l2h l2h.icn   # no longer compiles with iconc
+	$(ICONT) -o $@ $<   # no longer compiles with iconc
 
 sl2h.icn: l2h.nw
-	notangle -L'#line %-1L "%F"%N' -R'sl2h.icn' l2h.nw $(CPIF) sl2h.icn
+	notangle -L'#line %-1L "%F"%N' -R$@ $< $(CPIF) $@
 sl2h: sl2h.icn
-	$(ICONT) -o sl2h sl2h.icn   # no longer compiles with iconc
+	$(ICONT) -o $@ $<   # no longer compiles with iconc
 
 noindex: noindex.icn
-	$(ICONT) noindex.icn
+	$(ICONT) $<
 
 noidx: noidx.icn
-	$(ICONT) noidx.icn  # no longer compiles with iconc
+	$(ICONT) $<  # no longer compiles with iconc
 
 elide: elide.icn
-	$(ICONT) elide.icn
+	$(ICONT) $<
 
 pipedocs: pipedocs.icn
-	$(ICONT) pipedocs.icn
+	$(ICONT) $<
 
 pdcached: pdcached.icn
-	$(ICONT) pdcached.icn
+	$(ICONT) $<
 
 disambiguate: disambiguate.icn
-	$(ICONT) disambiguate.icn
+	$(ICONT) $<
 
 htmltoc: htmltoc.icn
-	$(ICONT) htmltoc.icn
+	$(ICONT) $<
diff --git a/src/lib/Makefile b/src/lib/Makefile
--- a/src/lib/Makefile
+++ b/src/lib/Makefile
@@ -11,15 +11,14 @@
 	chmod +x unmarkup emptydefn toascii nwmtime pipedocs h2a btdefn
 
 install: all
-	cp unmarkup emptydefn nwmtime btdefn $(LIB)
-	sed 's@|LIBDIR|@$(LIB)@g' pipedocs > $(LIB)/pipedocs
-	sed 's@|LIBDIR|@$(LIB)@g' toascii > $(LIB)/toascii
-	sed 's@|LIBDIR|@$(LIB)@g' h2a > $(LIB)/h2a
-	chmod +x $(LIB)/pipedocs $(LIB)/toascii $(LIB)/h2a
+	cp unmarkup emptydefn nwmtime btdefn $(DESTDIR)$(LIB)
+	sed 's@|LIBDIR|@$(LIB)@g' pipedocs > $(DESTDIR)$(LIB)/pipedocs
+	sed 's@|LIBDIR|@$(LIB)@g' toascii > $(DESTDIR)$(LIB)/toascii
+	sed 's@|LIBDIR|@$(LIB)@g' h2a > $(DESTDIR)$(LIB)/h2a
+	chmod +x $(DESTDIR)$(LIB)/pipedocs $(DESTDIR)$(LIB)/toascii $(DESTDIR)$(LIB)/h2a
 
 uninstall: 
-	for i in unmarkup emptydefn toascii nwmtime h2a btdefn; do rm -f $(LIB)/$$i; done
-	rm -f $(LIB)/pipedocs
+	for i in unmarkup emptydefn toascii nwmtime pipedocs h2a btdefn; do $(RM) $(DESTDIR)$(LIB)/$$i; done
 
 checkin:
 	ci -l $(CINAME) $(CIMSG) $(RCSFILES)
@@ -31,8 +30,10 @@
 	touch toascii
 
 toascii: toascii.nw
-	notangle -Rtoascii toascii.nw > toascii
+	notangle -R$@ $< > $@
+	chmod +x $@
 
-clean: ;	rm -f *.log *.blg *.dvi *.toc *.aux *.tex *~
+clean:
+	$(RM) *.log *.blg *.dvi *.toc *.aux *.tex *~
 clobber: clean
-	rm -f toascii
+	$(RM) toascii
diff --git a/src/shell/Makefile b/src/shell/Makefile
--- a/src/shell/Makefile
+++ b/src/shell/Makefile
@@ -1,7 +1,6 @@
 # Copyright 1993 by Norman Ramsey.  All rights reserved.
 # See file COPYRIGHT for more information.
 SHELL=/bin/sh
-LIB=/usr/public/pkg/noweb/lib
 
 EXEC=noweave noweb notangle noroff toroff
 SRCS=$(EXEC) tmac.w
@@ -9,9 +8,9 @@
 CINAME=
 CIMSG=
 
-all:	$(SRCS)
+all: $(SRCS)
 source: $(SRCS)
-touch:	$(SRCS)
+touch: $(SRCS)
 	touch $(SRCS)
 boot:
 	touch $(SRCS)
@@ -20,16 +19,18 @@
 	ci -l $(CINAME) $(CIMSG) $(RCSFILES)
 
 noweave: noweave.nw
-	notangle -Rnoweave noweave.nw > noweave
+	notangle -R$@ $< > $@
 
 notangle: notangle.nw
-	notangle -Rnotangle notangle.nw > notangle
+	notangle -R$@ $< > $@
 
-noweb: noweb.nw 
-	notangle -Rnoweb noweb.nw > noweb
+noweb: noweb.nw
+	notangle -R$@ $< > $@
 
 noroff toroff tmac.w: roff.nw
-	noweb -t roff.nw
+	noweb -t $<
 
-clean: ;	rm -f *.log *.blg *.dvi *.toc *.aux *.tex *~ *.nwt roff.mm
-clobber: clean ;	rm -f $(SRCS)
+clean:
+	$(RM) *.log *.blg *.dvi *.toc *.aux *.tex *~ *.nwt roff.mm
+clobber: clean
+	$(RM) $(SRCS)
diff --git a/src/tex/Makefile b/src/tex/Makefile
--- a/src/tex/Makefile
+++ b/src/tex/Makefile
@@ -14,15 +14,15 @@
 	ci -l $(CINAME) $(CIMSG) $(RCSFILES)
 
 nwmac.tex: support.nw
-	notangle -Rnwmac.tex support.nw > nwmac.tex
+	notangle -R$@ $< > $@
 
 noweb.sty: support.nw
-	notangle -Rnoweb.sty support.nw > noweb.sty
+	notangle -R$@ $< > $@
 
 support.tex: support.nw
-	noweave -delay -x support.nw > support.tex
+	noweave -delay -x $< > $@
 
-clean: 
-	/bin/rm -f *~ *.dvi *.aux *.log *.blg *.bbl *.toc
-	/bin/rm -f support.tex
+clean:
+	$(RM) *~ *.dvi *.aux *.log *.blg *.bbl *.toc
+	$(RM) support.tex
 clobber: clean
diff --git a/src/xdoc/Makefile b/src/xdoc/Makefile
--- a/src/xdoc/Makefile
+++ b/src/xdoc/Makefile
@@ -1,16 +1,20 @@
 WWW=$(HOME)/www/noweb
 SHELL=/bin/sh
 .SUFFIXES: .1 .7 .txt .ps
-.1.txt: ;	nroff -man $*.1 > $*.txt
-.1.ps: ;	psroff -t -man $*.1 > $*.ps
-.7.txt: ;	nroff -man $*.7 > $*.txt
-.7.ps: ;	psroff -t -man $*.7 > $*.ps
+.1.txt:
+	nroff -man $< > $@
+.1.ps:
+	psroff -t -man $< > $@
+.7.txt:
+	nroff -man $< > $@
+.7.ps:
+	psroff -t -man $< > $@
 
 MANPAGES=notangle.1   cpif.1   noweb.1   nodefs.1   noroots.1   noindex.1   \
-         nowebstyle.7   nowebfilters.7   nuweb2noweb.1   sl2h.1 htmltoc.1   \
+	 nowebstyle.7   nowebfilters.7   nuweb2noweb.1   sl2h.1 htmltoc.1   \
 	 noroff.1
 TXTPAGES=notangle.txt cpif.txt noweb.txt nodefs.txt noroots.txt noindex.txt \
-         nowebstyle.txt nowebfilters.txt nuweb2noweb.txt sl2h.txt htmltoc.txt   \
+	 nowebstyle.txt nowebfilters.txt nuweb2noweb.txt sl2h.txt htmltoc.txt   \
 	 noroff.txt
 SRCS=$(MANPAGES) $(TXTPAGES)
 
@@ -32,52 +36,52 @@
 	ci -l $(CINAME) $(CIMSG) $(RCSFILES)
 
 $(WWW)/onepage.ps: onepage.ps
-	cp onepage.ps $(WWW)
+	cp $< $@
 
 $(WWW)/guide.ps: guide.ps
-	cp guide.ps $(WWW)
+	cp $< $@
 
 $(WWW)/guide.html: guide.html
-	cp guide.html $(WWW)
+	cp $< $@
 
 notangle.1: manpage.nw ../shell/noweave.nw docdate.nw
-	notangle -t8 -Rnotangle.1  manpage.nw ../shell/noweave.nw docdate.nw | $(DOVERSION) > notangle.1
+	notangle -t8 -R$@ $^ | $(DOVERSION) > $@
 
 nowebstyle.7: manpage.nw ../tex/support.nw docdate.nw
-	notangle -t8 -Rnowebstyle.7 manpage.nw ../tex/support.nw docdate.nw | $(DOVERSION) > nowebstyle.7
+	notangle -t8 -R$@ $^ | $(DOVERSION) > $@
 
 nowebfilters.7: nowebfilters.nw docdate.nw
-	notangle -t8 nowebfilters.nw docdate.nw | $(DOVERSION) > nowebfilters.7
+	notangle -t8 $^ | $(DOVERSION) > $@
 
 noweb.1: manpage.nw docdate.nw
-	notangle -t8 -Rnoweb.1 manpage.nw docdate.nw | $(DOVERSION) > noweb.1
+	notangle -t8 -R$@ $^ | $(DOVERSION) > $@
 
 nodefs.1: nodefs.nw docdate.nw
-	notangle -t8 nodefs.nw docdate.nw | $(DOVERSION) > nodefs.1
+	notangle -t8 $^ | $(DOVERSION) > $@
 
 noroots.1: noroots.nw docdate.nw
-	notangle -t8 noroots.nw docdate.nw | $(DOVERSION) > noroots.1
+	notangle -t8 $^ | $(DOVERSION) > $@
 
 noindex.1: noindex.nw docdate.nw
-	notangle -t8 noindex.nw docdate.nw | $(DOVERSION) > noindex.1
+	notangle -t8 $^ | $(DOVERSION) > $@
 
 sl2h.1: sl2h.nw docdate.nw
-	notangle -t8 sl2h.nw docdate.nw | $(DOVERSION) > sl2h.1
+	notangle -t8 $^ | $(DOVERSION) > $@
 
 htmltoc.1: htmltoc.nw docdate.nw
-	notangle -t8 htmltoc.nw docdate.nw | $(DOVERSION) > htmltoc.1
+	notangle -t8 $^ | $(DOVERSION) > $@
 
 cpif.1: manpage.nw docdate.nw
-	notangle -t8 -Rcpif.1  manpage.nw docdate.nw | $(DOVERSION) > cpif.1
+	notangle -t8 -R$@ $^ | $(DOVERSION) > $@
 
 nuweb2noweb.1: manpage.nw docdate.nw
-	notangle -t8 -Rnuweb2noweb.1  manpage.nw docdate.nw | $(DOVERSION) > nuweb2noweb.1
+	notangle -t8 -R$@ $^ | $(DOVERSION) > $@
 
 noroff.1: noroff.nw docdate.nw
-	notangle -t8 noroff.nw docdate.nw | $(DOVERSION) > noroff.1
+	notangle -t8 $^ | $(DOVERSION) > $@
 
 wc.tex: ../../examples/wc.nw
-	(cd ../../examples; noweave -n -index wc.nw) > wc.tex
+	(cd ../../examples; noweave -n -index wc.nw) > $@
 
 techrep.dvi: techrep.tex wc.tex
 	latex '\scrollmode \input '"techrep"
@@ -88,23 +92,23 @@
 	while grep -s 'Rerun to get cross-references right' onepage.log; do latex '\scrollmode \input '"onepage"; done
 
 onepage.ps: onepage.dvi
-	dvips -P cmz -o onepage.ps onepage
+	dvips -P cmz -o $@ onepage
 
 guide.dvi: guide.tex
 	latex '\scrollmode \input '"guide"
 	while grep -s 'Rerun to get cross-references right' guide.log; do latex '\scrollmode \input '"guide"; done
 
 guide.ps: guide.dvi
-	dvips -P cmz -o guide.ps guide
+	dvips -P cmz -o $@ guide
 
 guide.uu: guide.ps
-	gzip < guide.ps > guide.ps.gz
-	uuencode guide.ps.gz < guide.ps.gz > guide.uu
+	gzip < $< > guide.ps.gz
+	uuencode guide.ps.gz < guide.ps.gz > $@
 
 guide.html: guide.dvi
-	sl2h guide.tex | htmltoc > guide.html
+	sl2h guide.tex | htmltoc > $@
 
-clean: ;	/bin/rm -f *.dvi *.log *.blg *~ wc.tex *.ps *.gz *.uu *.html
+clean:
+	$(RM) *.dvi *.log *.blg *~ wc.tex *.ps *.gz *.uu *.html
 clobber: clean
-	rm -f *.1 *.7 *.txt
-
+	$(RM) *.1 *.7 *.txt
